define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                pageSize: 25,
                pageList: [25, 50, 'All'],
                extend: {
                    index_url: 'order/order/index',
                    add_url: 'order/order/add',
                    edit_url: 'order/order/edit',
                    del_url: 'order/order/del',
                    multi_url: 'order/order/multi',
                    table: 'order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('#')},
                        // {field: 'admin_id', title: __('Admin_id')},
                        // {field: 'order_parent_sn', title: __('Order_parent_sn')},
                        {field: 'out_trade_no', title: __('Order_sn')},
                        {field: 'examine_switch', title: __('Examine_switch'), searchList: {"1":__('Yes'),"0":__('No')}, formatter: Table.api.formatter.toggle},
                        {field: 'pay_sn', title: __('Pay_sn')},
                        // {field: 'pay_name', title: __('Pay_name')},
                        // {field: 'pay_note', title: __('Pay_note')},
                        // {field: 'pay_scope', title: __('Pay_scope')},
                        // {field: 'buyer_mobile', title: __('Buyer_mobile')},
                        // {field: 'ship_address', title: __('Ship_address')},
                        // {field: 'ship_code', title: __('Ship_code')},
                        // {field: 'ship_note', title: __('Ship_note')},
                        // {field: 'ship_name', title: __('Ship_name')},
                        // {field: 'ship_oos', title: __('Ship_oos')},
                        // {field: 'order_tax', title: __('Order_tax')},
                        // {field: 'ship_fee', title: __('Ship_fee')},
                        // {field: 'discount_fee', title: __('Discount_fee')},
                        {field: 'order_fee', title: __('Order_fee')},
                        // {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'confirm_time', title: __('Confirm_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'pay_time', title: __('Pay_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'ship_time', title: __('Ship_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'ship_time_end', title: __('Ship_time_end')},
                        // {field: 'admin.id', title: __('Admin.id')},
                        // {field: 'admin.username', title: __('Admin.username')},
                        {field: 'buyer_name', title: __('Buyer_name')},
                        {field: 'buyer_status', title: __('Buyer_status'), searchList: {"unchecked":__('Buyer_status unchecked'),"same":__('Buyer_status same'),"different":__('Buyer_status different')}, formatter: Table.api.formatter.status},
                        {field: 'pay_status', title: __('Pay_status'), searchList: {"undeclared":__('Pay_status undeclared'),"submitted":__('Pay_status submitted'),"processing":__('Pay_status processing'),"success":__('Pay_status success'),"failure":__('Pay_status failure'),"except":__('Pay_status except')}, formatter: Table.api.formatter.status},
                        {field: 'ship_status', title: __('Ship_status'), searchList: {"undeclared":__('Ship_status undeclared'),"submitted":__('Ship_status submitted'),"processing":__('Ship_status processing'),"success":__('Ship_status success'),"failure":__('Ship_status failure'),"except":__('Ship_status except')}, formatter: Table.api.formatter.status},
                        {field: 'order_status', title: __('Order_status'), searchList: {"undeclared":__('Order_status undeclared'),"submitted":__('Order_status submitted'),"processing":__('Order_status processing'),"success":__('Order_status success'),"failure":__('Order_status failure'),"except":__('Order_status except')}, formatter: Table.api.formatter.status},
                        {field: 'admin.nickname', title: '管理员'},
                        // {field: 'admin.password', title: __('Admin.password')},
                        // {field: 'admin.salt', title: __('Admin.salt')},
                        // {field: 'admin.avatar', title: __('Admin.avatar')},
                        // {field: 'admin.email', title: __('Admin.email')},
                        // {field: 'admin.loginfailure', title: __('Admin.loginfailure')},
                        // {field: 'admin.logintime', title: __('Admin.logintime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'admin.createtime', title: __('Admin.createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'admin.updatetime', title: __('Admin.updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'admin.token', title: __('Admin.token')},
                        // {field: 'admin.status', title: __('Admin.status'), formatter: Table.api.formatter.status},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate, buttons:[
                            {
                                name: 'ajax',
                                text: '',
                                title: __('支付单报关'),
                                classname: 'btn btn-xs btn-default btn-magic btn-ajax',
                                icon: 'fa fa-magic',
                                url: '/api/hey_pay_customs/customs_push?order_id={ids}',
                                confirm: '确认发送',
                                extend: ' data-toggle="tooltip"',
                                success: function (data, ret) {
                                    Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                    //如果需要阻止成功提示，则必须使用return false;
                                    //return false;
                                },
                                error: function (data, ret) {
                                    console.log(data, ret);
                                    Layer.alert(ret.msg);
                                    return false;
                                }
                            },{
                                name: 'ajax',
                                text: '',
                                title: __('订单报关'),
                                classname: 'btn btn-xs btn-warning btn-magic btn-ajax',
                                icon: 'fa fa-magic',
                                url: '/api/hey_order_customs/customs_push?order_id={ids}',
                                confirm: '确认发送',
                                extend: ' data-toggle="tooltip"',
                                success: function (data, ret) {
                                    Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                    //如果需要阻止成功提示，则必须使用return false;
                                    //return false;
                                },
                                error: function (data, ret) {
                                    console.log(data, ret);
                                    Layer.alert(ret.msg);
                                    return false;
                                }
                            },
                            
                        ]}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {//渲染的方法
                examine_switch: function (value, row, index) {
                    //添加上btn-change可以自定义请求的URL进行数据处理
                    return '<a class="btn-change text-success" data-url="example/bootstraptable/change" data-id="' + row.id + '"><i class="fa ' + (row.examine_switch == 1 ? 'fa-toggle-on' : 'fa-toggle-off') + ' fa-2x"></i></a>';
                },
            },
        }
    };
    return Controller;
});